﻿CREATE PROCEDURE [maint].[UpdateDbConfig]
@DbName [sysname], @FullBackupSchedule INT, @FullBackupTime INT, @DiffBackupSchedule INT, @DiffBackupTime INT, @DiffBackupFrequency INT, @BackupSets INT, @DefragWeekSchedule INT, @DefragDaySchedule INT, @DefragThreshold INT, @CheckDbWeekSchedule INT, @CheckDbDaySchedule INT, @MaintenanceWindow INT, @UpdateStatsDaySchedule INT, @StatsLatency INT
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @RC int;
	SET @RC = 0

	UPDATE [config].[DbMaintenance]
	SET
		[FullBackupSchedule] = @FullBackupSchedule
		,[FullBackupTime] = @FullBackupTime
		,[DiffBackupSchedule] = @DiffBackupSchedule
		,[DiffBackupTime] = @DiffBackupTime
		,[DiffBackupFrequency] = @DiffBackupFrequency
		,[BackupSets] = @BackupSets
		,[DefragWeekSchedule] = @DefragWeekSchedule
		,[DefragDaySchedule] = @DefragDaySchedule
		,[DefragThreshold] = @DefragThreshold
		,[CheckDbWeekSchedule] = @CheckDbWeekSchedule
		,[CheckDbDaySchedule] = @CheckDbDaySchedule
		,[MaintenanceWindow] = @MaintenanceWindow
		,[UpdateStatsDaySchedule] = @UpdateStatsDaySchedule
		,[StatsLatency] = @StatsLatency
	WHERE ([DbName] = ISNULL(NULLIF(@DbName,'*'),[DbName]));
	SET @RC = @@ERROR;

EXIT_PROC:
	RETURN(@RC)
END;